package com.example.cca;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TableLayout;
import android.widget.TextView;


public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        textView = (TextView) findViewById(R.id.textView);
        tableLayout = (TableLayout) findViewById(R.id.tableLayout);
        button4 = (Button) findViewById(R.id.button4);
        button3 = (Button) findViewById(R.id.button3);
        button2 = (Button) findViewById(R.id.button2);
        button = (Button) findViewById(R.id.button);
        button8 = (Button) findViewById(R.id.button8);
        button7 = (Button) findViewById(R.id.button7);
        button6 = (Button) findViewById(R.id.button6);
        button5 = (Button) findViewById(R.id.button5);
        button12 = (Button) findViewById(R.id.button12);
        button11 = (Button) findViewById(R.id.button11);
        button10 = (Button) findViewById(R.id.button10);
        button9 = (Button) findViewById(R.id.button9);
        button16 = (Button) findViewById(R.id.button16);
        button15 = (Button) findViewById(R.id.button15);
        button14 = (Button) findViewById(R.id.button14);
        button25 = (Button) findViewById(R.id.button25);
        button20 = (Button) findViewById(R.id.button20);
        button19 = (Button) findViewById(R.id.button19);
        button18 = (Button) findViewById(R.id.button18);
        button17 = (Button) findViewById(R.id.button17);
        button24 = (Button) findViewById(R.id.button24);
        button23 = (Button) findViewById(R.id.button23);
        button22 = (Button) findViewById(R.id.button22);
        button21 = (Button) findViewById(R.id.button21);
        button23.setOnClickListener(this);
        button20.setOnClickListener(this);
        button19.setOnClickListener(this);
        button18.setOnClickListener(this);
        button16.setOnClickListener(this);
        button15.setOnClickListener(this);
        button14.setOnClickListener(this);
        button12.setOnClickListener(this);
        button11.setOnClickListener(this);
        button10.setOnClickListener(this);
        button17.setOnClickListener(this);
        button25.setOnClickListener(this);
        button9.setOnClickListener(this);
        button5.setOnClickListener(this);
    }


    private TextView textView;
    private TableLayout tableLayout;
    private Button button4;
    private Button button3;
    private Button button2;
    private Button button;
    private Button button8;
    private Button button7;
    private Button button6;
    private Button button5;
    private Button button12;
    private Button button11;
    private Button button10;
    private Button button9;
    private Button button16;
    private Button button15;
    private Button button14;
    private Button button25;
    private Button button20;
    private Button button19;
    private Button button18;
    private Button button17;
    private Button button24;
    private Button button23;
    private Button button22;
    private Button button21;

    public void onClick(View view) {





        String str = textView.getText().toString();
        if(str.equals("0")) {
            str = "";
        }
        switch (view.getId()) {
            case R.id.button23:
                str+="0";
                textView.setText(str);
                break;
            case R.id.button20:
                str+="1";
                textView.setText(str);
                break;
            case R.id.button19:
                str+="2";
                textView.setText(str);
                break;
            case R.id.button18:
                str+="3";
                textView.setText(str);
                break;
            case R.id.button16:
                str+="4";
                textView.setText(str);
                break;
            case R.id.button15:
                str+="5";
                textView.setText(str);
                break;
            case R.id.button14:
                str+="6";
                textView.setText(str);
                break;
            case R.id.button12:
                str+="7";
                textView.setText(str);
                break;
            case R.id.button11:
                str+="8";
                textView.setText(str);
                break;
            case R.id.button10:
                str+="9";
                textView.setText(str);
                break;
            case R.id.button17:
                str+="+";
                textView.setText(str);
                break;
            case  R.id.button25:
                str +="-";
                textView.setText(str);
                break;
            case R.id.button9:
                str+="×";
                textView.setText(str);
                break;
            case R.id.button5:
                str+="÷";
                textView.setText(str);
                break;
            case R.id.button3:
                str="0";
                textView.setText(str);
                break;

        }



    }

    @Override
    public void onPointerCaptureChanged(boolean hasCapture) {

    }
}